import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const usePortStore = defineStore('prot', () => {
  const port = ref()
  const afterURL = ref('')
  function setPort (data) {
    port.value = data
  }
  function getPort () {
    return port.value.port
  }
  function getUserInfo () {
    return port.value.userinfo
  }
  function setUrl (url) {
    afterURL.value = url
  }


  //是否失效
  function isInvalid () {
    if (!port.value?.time && !port.value?.port || !port.value?.userinfo) return true
    return (new Date().getTime() - port.value.time) >= 3600000 * 12
  }
  return { port, setPort, getPort, isInvalid, getUserInfo, afterURL, setUrl }
}, { persist: true })
